#!/bin/sh
#
#fengyz @ tz 
#the handler script for wlan button
if [ -e /tmp/.in_peripheral_test ]; then
	touch /tmp/.wifi_button_press
fi

[ "${ACTION}" = "released" ] || exit 0


logger "$BUTTON pressed for $SEEN seconds"

if [ -e /tmp/.in_peripheral_test ]; then
	rm /tmp/.wifi_button_press
	exit
fi

if [ "$SEEN" -lt 1 ]
then
        res=` uci get wireless.@wifi-iface[0].disabled`
        if [[ $res == "1" ]];then
	        echo "Start wifi... " > /dev/console

	        echo "enable wifi... " > /dev/console
		uci set   wireless.@wifi-iface[0].disabled=0
		uci set   wireless.@wifi-iface[1].disabled=0
		uci set   mutilssid.@wifi-iface[0].disabled=0
		uci set   mutilssid.@wifi-iface[1].disabled=0
		uci set   mutilssid.@wifi-iface[2].disabled=0
		uci set   mutilssid.@wifi-iface[3].disabled=0
		/sbin/wifi 
        else
	        echo "Stop wifi... " > /dev/console
	        echo "disable wifi... " > /dev/console
		uci set  wireless.@wifi-iface[0].disabled=1
		uci set  wireless.@wifi-iface[1].disabled=1
		uci set   mutilssid.@wifi-iface[0].disabled=1
		uci set   mutilssid.@wifi-iface[1].disabled=1
		uci set   mutilssid.@wifi-iface[2].disabled=1
		uci set   mutilssid.@wifi-iface[3].disabled=1
		/sbin/wifi  down 
        fi
	
	uci commit wireless
	uci commit mutilssid
	return 0

elif [ "$SEEN" -gt 5 ]
then
    echo "pressed 5 sec"
fi

return 0
